package com.travelsky.app.security.manager;


import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.travelsky.app.persistence.User;
import com.travelsky.app.util.PaginationSupport;

public interface IUserService {
	
	/**
	 * 根据条件分页查询用户
	 * @param userCriteria  查询条件
	 * @param startIndex 起始元素标号
	 * @return PaginationSupport<Role>    
	 */
	@Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT )
	public PaginationSupport<User> findUserList(DetachedCriteria userCriteria,int startIndex);
	
	
	/**
	 * 用户更新
	 * @param  待修改的用户  
	 */
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT ,rollbackFor = Exception.class)
	public void updateUser(User user);
	
	/**
	 * 修改某用户的密码
	 * @param  newEncodedPassword 加密过的新密码 
	 * @param  userName 待修改的用户    
	 */
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT ,rollbackFor = Exception.class)
	public void updatePassword(String newEncodedPassword,String userName);
	

	/**
	 * 根据用户名查询用户是否存在
	 * @param userName  用户名
	 * @return true 存在 false 不存在
	 */
	@Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT )
	public boolean existUserByName(String userName);
	/**
	 * 添加用户
	 *   
	 */
	@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT ,rollbackFor = Exception.class)
	public void addUser(User user);
	

	/**
	 * 根据用户名查询用户 use hibernate query cache
	 * @param userName  用户名
	 * @return User  如果没找到返回null
	 */
	@Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT )
	public User findUserByName(String userLoginName);
	
	/**
	 * 根据用户名查询用户 use hibernate query cache
	 * @param userId  用户ID
	 * @return User  如果没找到返回null
	 */
	@Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT )
	public User findUserById(String userId);

	/**
	 * 根据OfficeCode查询此OfficeCode下的代理人是否已经存在 use hibernate query cache
	 * @param officeCode  
	 * @return true 存在  false 不存在
	 */
	@Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT )
	public boolean existUserByOfficeCode(String officeCode);
	

	/**
	 * 查询所有代理人
	 * @return List<AgentUser>  代理人列表
	 */
	@Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT )
	public List<User> getAllAgentUser() ;

	/**
	 * 根据用户ID查询代理人
	 * @param userId 用户ID
	 * @return 如果没找到返回null
	 */
//	public AgentUser findAgentUserById(Long userId);
	
	/**
	 * 获取所有航线员数据
	 * @return List<User> 航线员列表
	 */
	public List<User> getAllAirLineUser();

	@Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT )
	public boolean existUserByIataCode(String iataCode);

//	@Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT )
//	public List<AgentUser> findAgentsLevel(List<String> agentInputLevel);

//	@Transactional(propagation = Propagation.SUPPORTS,isolation = Isolation.DEFAULT )
//	public List<AgentUser> findAgentUserByIds(List<Long> agentId);
	
}
